Component({
  data: {
    active: 0,
    list: [
      {
        url: '/pages/main/main',
        text: '首页',
        icon: '/static/images/tab-bar/home0.png',
        activeIcon: '/static/images/tab-bar/home1.png'
      },
      {
        url: '/pages/explore/explore',
        text: '发现',
        icon: '/static/images/tab-bar/recruit0.png',
        activeIcon: '/static/images/tab-bar/recruit1.png'
      },
      {
        url: '/pages/publish/index',
        text: '发布',
        icon: '/static/images/tab-bar/supply0.png',
        activeIcon: '/static/images/tab-bar/supply1.png'
      },
      {
        url: '/pages/message/index',
        text: '消息',
        icon: '/static/images/tab-bar/supply0.png',
        activeIcon: '/static/images/tab-bar/supply1.png'
      },
      {
        url: '/pages/me/me',
        text: '我的',
        icon: '/static/images/tab-bar/me0.png',
        activeIcon: '/static/images/tab-bar/me1.png'
      }
    ]
  },

  methods: {
    onChange(event) {
      console.log(event.detail)
      this.setData({ active: event.detail })
      if (event.detail == 2) {
        wx.navigateTo({
          url: this.data.list[event.detail].url
        })
        return
      }
      wx.switchTab({
        url: this.data.list[event.detail].url
      })
    },

    init() {
      const page = getCurrentPages().pop()
      console.log(page)
      this.setData({
        active: this.data.list.findIndex(
          (item) => item.url === `/${page.route}`
        )
      })
    }
  }
})
